home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 6.4 KB | 198 lines | [TEXT/MPS ] |
- // Copyright (c) 1993 Regents of the University of Michigan. All rights reserved.
-
- /* ==========================================================================
- AOCE utility routines for the ldap CSAM.
-
- Written by: Gavin Eadie • The University of Michigan Information Systems
- Phone: (313) 936-0816
- AppleLink: A67
- Internet: gavin@umich.edu
-
- ========================================================================== */
-
- #include "SKEL•CSAM.h"
- #include "AOCE•Util.h"
-
- #include <string.h> // strxxx + memxxx routines
-
- pascal Boolean AttrValue_Callback(long clientData, const Attribute *attribute);
- void MakePersonalRecordID(RecordID * recordID, const CreationID * creationID);
-
- #define kAttrBuffer_Len 256
-
- typedef struct AttributeCopyInfo {
- Ptr buffer_Ptr;
- Size buffer_Len;
- Boolean AttrValue_OK;
- } AttributeCopyInfo;
-
- /* ==========================================================================
- GetAttributeValue •
-
- this routine returns a single attribute value from a record. it's
- used to get information out of the directory setup information
- -------------------------------------------------------------------------- */
- OSErr GetAttributeValue(const CreationID * cid, short dsRef,
- AttributeType * attribType, void * attrBuffer,
- Size attrBufferSize) {
- DirParamBlock cat_pb;
- Ptr AttrBuffer_Ptr;
- RecordIDPtr recordList[1];
- AttributeTypePtr attrList[1];
- RecordID recordID;
- AttributeCopyInfo callbackInfo;
- OSErr Dir_Error;
-
- callbackInfo.buffer_Ptr = attrBuffer;
- callbackInfo.buffer_Len = attrBufferSize;
- callbackInfo.AttrValue_OK = false;
-
- MakePersonalRecordID(&recordID, cid);
-
- recordList[0] = (RecordIDPtr)&recordID;
-
- attrList[0] = attribType;
- AttrBuffer_Ptr = NewPtr(kAttrBuffer_Len);
- if (noErr != MemError())
- return MemError();
-
- memset(&cat_pb, '\0', sizeof(DirParamBlock));
-
- cat_pb.header.ioCompletion = nil;
- cat_pb.header.clientData = (long)&callbackInfo;
- cat_pb.lookupGetPB.serverHint.aNet = 0;
- cat_pb.lookupGetPB.serverHint.aNode = 0;
- cat_pb.lookupGetPB.serverHint.aSocket = 0;
- cat_pb.lookupGetPB.dsRefNum = dsRef;
- cat_pb.lookupGetPB.identity = 0;
- cat_pb.lookupGetPB.aRecordList = recordList;
- cat_pb.lookupGetPB.attrTypeList = attrList;
- cat_pb.lookupGetPB.recordIDCount = 1;
- cat_pb.lookupGetPB.attrTypeCount = 1;
- cat_pb.lookupGetPB.includeStartingPoint = true;
- cat_pb.lookupGetPB.getBuffer = AttrBuffer_Ptr;
- cat_pb.lookupGetPB.getBufferSize = kAttrBuffer_Len;
- cat_pb.lookupGetPB.startingRecordIndex = 1;
- cat_pb.lookupGetPB.startingAttrTypeIndex = 1;
-
- OCESetCreationIDtoNull(&cat_pb.lookupGetPB.startingAttribute.cid);
-
- Dir_Error = DirLookupGet(&cat_pb, false);
- if (noErr == Dir_Error || kOCEMoreData == Dir_Error) {
- cat_pb.lookupParsePB.eachRecordID = nil;
- cat_pb.lookupParsePB.eachAttrType = nil;
- cat_pb.lookupParsePB.eachAttrValue = AttrValue_Callback;
- Dir_Error = DirLookupParse(&cat_pb, false);
- }
-
- if ((noErr == Dir_Error) && !callbackInfo.AttrValue_OK)
- Dir_Error = kNoRecords;
-
- DisposePtr(AttrBuffer_Ptr);
-
- return (Dir_Error);
- }
-
-
- /* ==========================================================================
- AttrValue_Callback •
-
- -------------------------------------------------------------------------- */
- pascal Boolean AttrValue_Callback(long clientData, const Attribute * attribute) {
- AttributeCopyInfo * callbackInfo;
- Size moveSize;
-
- callbackInfo = (AttributeCopyInfo *)clientData;
-
- moveSize = attribute->value.dataLength;
- if (moveSize > callbackInfo->buffer_Len)
- moveSize = callbackInfo->buffer_Len;
-
- BlockMove(attribute->value.bytes, callbackInfo->buffer_Ptr, moveSize);
-
- callbackInfo->AttrValue_OK = true;
- return (false);
- }
-
-
- /* ==========================================================================
- AddAttribute • add an attribute value to a record
-
- -------------------------------------------------------------------------- */
- OSErr AddAttribute(const CreationID * cid, short dsRef,
- AttributeType * attribType, void * data,
- unsigned long dataLength, AttributeTag tag) {
- DirParamBlock cat_pb;
- Attribute att_pb;
- RecordID recordID;
- OSErr Dir_Error;
-
- MakePersonalRecordID(&recordID, cid);
-
- OCECopyRString((const RStringPtr)attribType, (RStringPtr)&att_pb.attributeType, kAttributeTypeMaxBytes);
- OCESetCreationIDtoNull(&att_pb.cid);
- att_pb.value.tag = tag;
- att_pb.value.dataLength = dataLength;
- att_pb.value.bytes = (Ptr)data;
-
- cat_pb.addAttributeValuePB.serverHint.aNet = 0;
- cat_pb.addAttributeValuePB.serverHint.aNode = 0;
- cat_pb.addAttributeValuePB.serverHint.aSocket = 0;
- cat_pb.addAttributeValuePB.dsRefNum = dsRef;
- cat_pb.addAttributeValuePB.identity = 0;
- cat_pb.addAttributeValuePB.aRecord = &recordID;
- cat_pb.addAttributeValuePB.attr = &att_pb;
-
- Dir_Error = DirAddAttributeValue(&cat_pb, false);
-
- return (Dir_Error);
- }
-
- /* ==========================================================================
- MakePersonalRecordID •
-
- this convenience function fills in a RecordID given a creation ID,
- since a fully specified record ID for a personal directory contains
- only a creation ID
- -------------------------------------------------------------------------- */
- void MakePersonalRecordID(RecordID * recordID, const CreationID * creationID) {
- recordID->rli = nil;
- OCECopyCreationID(creationID, &recordID->local.cid);
- recordID->local.recordName = nil;
- recordID->local.recordType = nil;
- }
-
-
- // --------------------------------------------------------------------------
- // copy an RStr to a given CStr and return the address of the CStr ...
- //
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // RStr: | |(n)|a b c d e f g ...
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -
- // CStr: |a|b|c|d|e|f|g|h| | |
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -
- // [0]
- // --------------------------------------------------------------------------
- char * RToCString(RStringPtr R_String, char * C_String) {
-
- BlockMove(R_String->body, C_String, R_String->dataLength);
- C_String[R_String->dataLength] = 0;
- return (C_String);
-
- }
-
-
- // --------------------------------------------------------------------------
- // look for the Target character in an RStr and return true if found
- // --------------------------------------------------------------------------
- Boolean rstrchr(RStringPtr R_String, short Target) {
- char * RStr_Body = R_String->body;
- short RStr_Index = 0;
-
- while (RStr_Index <= R_String->dataLength) {
- if (Target == RStr_Body[RStr_Index++]) return (true);
- }
-
- return (false);
- }
-